package com.company;

import java.util.Arrays;

public class Main {
    private char[][] a;

    public static int maximalRectangle(char [][] matrix){
        int result = 0;
        int m = matrix.length,n = matrix[0].length;
        int [][] dp = new int[m][n];
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(matrix[i][j] == '1'){
                    dp[i][j] = j==0?1:(dp[i][j-1]+1);
                    int width = Integer.MAX_VALUE;
                    for(int k=i;k>=0;k--){
                        width = Math.min(width,dp[k][j]);
                        result = Math.max(result,width*(i-k+1));
                    }
                }
            }
        }
        return result;
    }
    public static void main(String[] args) {
	// write your code here
        char [][] a = {{'1','0','1','0','0'},
                      {'1','0','1','1','1'},
                      {'1','1','1','1','1'},
                      {'1','0','0','1','0'}};
        System.out.println(maximalRectangle(a));
    }
}
